﻿using AuthCenter.Domain;
using AuthCenter.ErorCode;
using AuthCenter.Infrastructure;
using AuthCenter_API.Read.Applications.Commands.User;
using MediatR;

namespace AuthCenter_API.Read.Applications.CommandHandlers.User
{
    public class ShiQueryCommandHandler : IRequestHandler<ShiQueryCommand, APIResult<List<ShiModel>>>
    {
        private readonly IBaseRepository<ShiModel> _shiRepository;

        public ShiQueryCommandHandler(IBaseRepository<ShiModel> shiRepository)
        {
            _shiRepository = shiRepository;
        }

        public Task<APIResult<List<ShiModel>>> Handle(ShiQueryCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<ShiModel>> result = new APIResult<List<ShiModel>>();
            result.Code = APIEnum.QuerySuccess;
            result.Message = APIEnum.QuerySuccess.Desc();
            var m = _shiRepository.GetAll().Where(x => x.ShengId == request.ShengId).ToList();
            result.Data = m;
            return Task.FromResult(result);
        }
    }
}
